GoodReadsLookup

data class GoodReadsLookup(    val title: String,     val author: String? = null,     val includeAuthorInSearch: Boolean = author != null) : CompilableToString

Find books on GoodReads.

Samples

import ch.derlin.grmetafetcher.GoodReadsLookup
import ch.derlin.grmetafetcher.GoodReadsMetadata
import ch.derlin.grmetafetcher.GoodReadsPaginatedSearchResults
import ch.derlin.grmetafetcher.Retry
import ch.derlin.grmetafetcher.RetryConfiguration
fun main() { 
   //sampleStart 
   val p: (GoodReadsMetadata) -> Unit = { println(it.toCompilableString()) }

// very shot titles need authors to match
p(GoodReadsMetadata.lookup(title = "substance", author = "claro"))
// Authors will match without the initials, and can be ignored in search for specific/long enough titles
p(GoodReadsMetadata.lookup("House of Leaves", "Mark Danielewski", includeAuthorInSearch = false))
// Subtitle can be ignored in lookup
p(GoodReadsMetadata.lookup(title = "Masters of Doom"))

// The same can be achieved using GoodReadsLookup // accents don't matter
p(GoodReadsLookup(title = "la cle de salomon").findBestMatch().getMetadata())

// If you know the URL or GoodReads ID, you can use them directly
p(GoodReadsMetadata.fromGoodReadsId("41940388")) 
   //sampleEnd
}
import ch.derlin.grmetafetcher.GoodReadsLookup
import ch.derlin.grmetafetcher.GoodReadsMetadata
import ch.derlin.grmetafetcher.GoodReadsPaginatedSearchResults
import ch.derlin.grmetafetcher.Retry
import ch.derlin.grmetafetcher.RetryConfiguration
fun main() { 
   //sampleStart 
   val reader = java.util.Scanner(System.`in`)

print("Enter a book title: ")
val title = reader.nextLine()
print("Enter an author (press enter for none): ")
val author = reader.nextLine().ifBlank { null }

val matches = GoodReadsLookup(title = title, author = author).getMatches()

println("\nResults:")
matches.indices.take(10).forEach { println(" [$it] ${matches[it].title} by ${matches[it].authorsStr}") }
print("\nEnter the index of the book you want: ")
val index = reader.nextInt()

println("\nMetadata:")
println(matches[index].getMetadata().toCompilableString()) 
   //sampleEnd
}

Constructors

Link copied to clipboard
fun GoodReadsLookup(    title: String,     author: String? = null,     includeAuthorInSearch: Boolean = author != null)

Functions

Link copied to clipboard
fun findBestMatch(): GoodReadsSearchResult

Search and try to find the best match for the given title (and maybe authors) on GoodReads.

Link copied to clipboard
fun getMatches(): List<GoodReadsSearchResult>

Get the list of matches for the given search query (see searchUrl). Note that only the results appearing on the first page are returned, hence a maximum of 20 results.

Link copied to clipboard
fun getMatchesPaginated(): GoodReadsPaginatedSearchResults

Get the list of matches for the given search query (see searchUrl), paginated.

Link copied to clipboard
open override fun toCompilableString(): String

Should return the String representation of this class as a compilable snippet (can be copy-pasted into Kotlin code).

Properties

Link copied to clipboard
val author: String? = null

The (partial) author(s) to look for. If multiple authors, they can be separated by any of , , or &. If you plan to use findBestMatch, the author should at least match the first author in the form "FirstName Lastname".

Link copied to clipboard
val includeAuthorInSearch: Boolean

Whether to use the author in the search query (search all fields) or not (search title only). This is useful because except when the title is very generic, a search in title only gives better results.

Link copied to clipboard
val searchUrl: String

Search URL on GoodReads for. Note that the title (and maybe authors) are sanitized for better results.

Link copied to clipboard
val title: String

The (partial) title to look for. If you plan to use findBestMatch, the title should be "exact".

Sources

Link copied to clipboard